<template>
  <div class="zh-evaluation-criteria">
    <nav-header></nav-header>
    <div class="zh-table">
      <div class="zh-table-open clear">
        <div class="zh-open-left fl">
          <div class="open-width">
            <el-input
              v-model="listParam.keyword"
              placeholder="请输入标准名、撰写人搜索"
              @keyup.enter.native="searchFunc"
            ></el-input>
          </div>
          <el-button type="primary" @click="searchFunc">搜索</el-button>
          <el-button type="primary" @click="reset">重置</el-button>
        </div>
        <div class="zh-open-right fr">
          <el-button type="primary" @click="newStandard"
            >新增评估标准</el-button
          >
        </div>
      </div>
      <div class="zh-table-contents">
        <el-table :data="listData" border max-height="600" style="width: 100%">
          <el-table-column
            type="index"
            :index="typeIndex"
            label="序号"
            align="center"
            show-overflow-tooltip
            width="50"
          >
          </el-table-column>
          <el-table-column
            prop="name"
            label="标准名称"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="user_name"
            label="撰写人"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            :prop="$store.state.checkLevel ? 'classify_name' : 'subject_name'"
            label="适用"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="use_count"
            label="使用次数"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="create_time"
            label="最近更新"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="5"
            label="操作"
            align="center"
            width="130"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <el-button @click="detailJump(scope.row.id)" type="text"
                >查看</el-button
              >
              <el-button @click="editJump(scope.row.id)" type="text"
                >编辑</el-button
              >
              <el-button
                @click="delete_confirm(scope.row)"
                type="text"
                class="delete-button"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="table-pagination" v-show="total_number > 10">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="listParam.page_index"
            :page-sizes="[10, 20, 30, 40, 50, 100]"
            :page-size="listParam.page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total_number"
          >
          </el-pagination>
          <div class="pagination-button">
            <el-button
              @click="getList"
              type="primary"
              icon="el-icon-refresh"
              circle
              title="刷新数据"
              size="mini"
            >
            </el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      listData: [],
      listParam: {
        status: 0,
        classify_id: "",
        keyword: "",
        page_index: 1,
        page_size: 10,
      },
      total_number: 0,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    searchFunc() {
      this.listParam.page_index = 1;
      this.listParam.page_size = 10;
      this.getList();
    },
    reset() {
      this.listParam = {
				status: 0,
        classify_id: "",
        keyword: "",
        page_index: 1,
        page_size: 10,
      };
      this.getList();
    },
    detailJump(id) {
      this.$router.push("/teaching/research/detail-standard/" + id);
    },
    editJump(id) {
      this.$router.push("/teaching/research/new-standard/" + id);
    },
    newStandard() {
      this.$router.push("/teaching/research/new-standard");
    },
    // 序号
    typeIndex(index) {
      return (
        index + (this.listParam.page_index - 1) * this.listParam.page_size + 1
      );
    },
    getList() {
      let success = (data) => {
        console.log(data);
        this.listData = data.data.data;
        this.total_number = data.data.data_sum;
      };
      //执行请求，并将回调方法变成config成员以便鉴权过期可以执行
      this.$ajax.get("api/network/eva_standard", {
        params: this.listParam,
        func: { success: success },
      });
    },
    delete_confirm(obj) {
      let yes = (data) => {
        this.delete(obj.id, 0);
      };
      let cancel = (data) => {};
      this.e_confirm({
        yes: yes,
        cancel: cancel,
        txt: "确定将 " + obj.name + " 删除吗？",
      });
    },
    delete(id, status) {
      let success = (data) => {
        this.$message.success(data.msg);

        if (this.listData.length - this.rowLen === 0) {
          if (this.listParam.page_index > 1) {
            this.listParam.page_index--;
          } else {
            this.listParam.page_index = 1;
          }
        }

        this.getList();
      };
      this.$ajax.delete("api/network/eva_standard", {
        params: { id: id, status: status },
        func: { success: success },
      });
    },
    handleSizeChange(val) {
      this.listParam.page_index = 1;
      this.listParam.page_size = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listParam.page_index = val;
      this.getList();
    },
  },
};
</script>
<style lang="scss">
.zh-evaluation-criteria {
  .el-table__body-wrapper table tbody {
    td:nth-child(7) {
      padding: 0;
    }
  }
}
</style>